package com.knowledge.graph.mapper;

import com.knowledge.graph.model.entity.Relation;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author jiwenlong
 * @description: 对应“关系”对象的数据库操作
 * @date 2023/11/11 0:08
 * // * @version 1.0
 */
@Repository
public interface RelationRepository extends Neo4jRepository<Relation, Long> {

    @Query("MATCH p=()-[r:`关系`]->() RETURN p")
    List<Relation> getAll();

    @Query("MATCH p=(n:`节点`{type:$nodeType})-[r:`关系`]->() RETURN p")
    List<Relation> getByNodeType(@Param("nodeType") String nodeType);

    @Query("MATCH p=(n:`节点`{name:$nodeName,type:$nodeType})-[r:`关系`*..6]->() WHERE length(p)=$layers RETURN p")
    List<Relation> getByNodeID(@Param("nodeName") String nodeName, @Param("nodeType") String nodeType, @Param("layers") Integer layers);
}
